package com.bolt.core.view.components;

import com.bolt.common.BoltConstants;
import com.bolt.common.utils.DateUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created by Administrator on 2017/9/15.
 */
public class DateInput extends InputText {

    private static final String TEMPLATE = "date";

    public DateInput() {
        super();
    }

    @Override
    protected String getDefaultTemplate() {
        return TEMPLATE;
    }


    @Override
    protected void evaluateValue(HttpServletRequest request) {
        super.evaluateValue(request);
        Object value = request.getAttribute(BoltConstants.FORM_ITME_VALUE_ATTRIBUTE);
        if (value instanceof Date) {
            String format = parameters.get("format") != null ? (String) parameters.get("format") : DateUtil.DEFAULT_DATE_FORMAT;
            String formatDate = DateUtil.formatDate((Date) value, format);
            request.setAttribute(BoltConstants.FORM_ITME_VALUE_ATTRIBUTE, formatDate);
        }
    }
}
